import 'package:flutter/material.dart';
import 'package:flutter_aggregate/model/plant/constants.dart';

class TitleWithMoreBtn extends StatelessWidget {
  const TitleWithMoreBtn({
    Key? key, 
    required this.title, 
    required this.preess,
  }) : super(key: key);

  final String title;
  final Function preess;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: palntKDefaultPadding),
      child: Row(
        children: [
          TitleWithCustomUnderline(
            text: title,
          ),
          const Spacer(),
          SizedBox(
            width: 90,
            child: TextButton(
              style: TextButton.styleFrom(
                backgroundColor: palntKPrimaryColor,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20)
                )
              ),
              onPressed: () => preess(), 
              child: const Text(
                '更多',
                style: TextStyle(
                  color: Colors.white
                ),
              )
            ),
          )
        ],
      ),
    );
  }
}

class TitleWithCustomUnderline extends StatelessWidget {
  const TitleWithCustomUnderline({
    Key? key, 
    required this.text,
  }) : super(key: key);

  final String text;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Padding(
          padding: const EdgeInsets.only(
            left: palntKDefaultPadding / 4
          ),
          child: Text(
            text,
            style: const TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.bold
            ),
          ),
        ),
        Positioned(
          bottom: 0,
          left: 0,
          right: 0,
          child: Container(
            margin: const EdgeInsets.only(
              right: palntKDefaultPadding / 4
            ),
            height: 7,
            color: palntKPrimaryColor.withOpacity(.2),
          )
        )
      ],
    );
  }
}
